package com.hzo.great.leisuregreat.fragments;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.hzo.great.leisuregreat.R;
import com.hzo.great.leisuregreat.utils.SharedPreferencesUtils;
import com.hzo.great.leisuregreat.views.AddressManagement;
import com.hzo.great.leisuregreat.views.LoginActivity;
import com.hzo.great.leisuregreat.views.OrderActivity;
import com.hzo.great.leisuregreat.views.RegistActivity;
import com.hzo.great.leisuregreat.views.SetActivity;
import com.hzo.great.leisuregreat.views.UserFeedbackActivity;

import butterknife.ButterKnife;
import butterknife.OnClick;

public class MineFragment extends Fragment {

    RelativeLayout message;
    TextView unReadNum, login, regist, user;
    ImageView set;
    LinearLayout myOrder, waitPay, waitSend, waitReceive, allOrder, phoneRecycle, recycleOrder, addressManagement, userFeedback, servicePhoneNum, loginAndRegist;

    Activity activity;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        activity = (Activity) context;
    }

    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.mine_fragment, null);
        initView(view);
        ButterKnife.bind(this,view);
        return view;
    }

    public void initView(View view) {
        message = (RelativeLayout) view.findViewById(R.id.message);

        unReadNum = (TextView) view.findViewById(R.id.unReadNum);
        login = (TextView) view.findViewById(R.id.login);
        regist = (TextView) view.findViewById(R.id.regist);
        user = (TextView) view.findViewById(R.id.user);

        set = (ImageView) view.findViewById(R.id.set);

        myOrder = (LinearLayout) view.findViewById(R.id.myOrder);
        waitPay = (LinearLayout) view.findViewById(R.id.waitPay);
        waitSend = (LinearLayout) view.findViewById(R.id.waitSend);
        waitReceive = (LinearLayout) view.findViewById(R.id.waitReceive);
        allOrder = (LinearLayout) view.findViewById(R.id.allOrder);
        phoneRecycle = (LinearLayout) view.findViewById(R.id.phoneRecycle);
        recycleOrder = (LinearLayout) view.findViewById(R.id.recycleOrder);
        addressManagement = (LinearLayout) view.findViewById(R.id.addressManagement);
        userFeedback = (LinearLayout) view.findViewById(R.id.userFeedback);
        servicePhoneNum = (LinearLayout) view.findViewById(R.id.servicePhoneNum);
        loginAndRegist = (LinearLayout) view.findViewById(R.id.loginAndRegist);

        if (SharedPreferencesUtils.getString("access_token","") != null && !SharedPreferencesUtils.getString("access_token","").equals("")){
            loginAndRegist.setVisibility(View.GONE);
            user.setVisibility(View.VISIBLE);
            user.setText(SharedPreferencesUtils.getString("phoneNumber",""));
        }
    }

    @OnClick({R.id.message,R.id.login,R.id.regist,R.id.set,R.id.myOrder,R.id.waitPay,R.id.waitSend,R.id.waitReceive,R.id.allOrder,R.id.phoneRecycle,
            R.id.recycleOrder,R.id.addressManagement,R.id.userFeedback,R.id.servicePhoneNum})
    public void onClick(View view) {

        switch (view.getId()){
            case R.id.message:
                showToast("消息");
                break;

            case R.id.login:
                startActivity(new Intent(activity,LoginActivity.class));
                break;

            case R.id.regist:
                startActivity(new Intent(activity,RegistActivity.class));
                break;

            case R.id.set:
                startActivity(new Intent(activity,SetActivity.class));
                break;

            case R.id.myOrder:
                startActivity(new Intent(activity,OrderActivity.class));
                break;

            case R.id.waitPay:
                startActivity(new Intent(activity,OrderActivity.class).putExtra("status",1));
                break;

            case R.id.waitSend:
                startActivity(new Intent(activity,OrderActivity.class).putExtra("status",2));
                break;

            case R.id.waitReceive:
                startActivity(new Intent(activity,OrderActivity.class).putExtra("status",3));
                break;

            case R.id.allOrder:
                startActivity(new Intent(activity,OrderActivity.class));
                break;

            case R.id.phoneRecycle:
                showToast("敬请期待");
                break;

            case R.id.recycleOrder:
                showToast("敬请期待");
                break;

            case R.id.addressManagement:
                startActivity(new Intent(activity,AddressManagement.class));
                break;
            case R.id.userFeedback:
                //startActivity(new Intent(activity, UserFeedbackActivity.class));
                showToast("敬请期待");
                break;
            case R.id.servicePhoneNum:
                showToast("客服电话");
                break;

        }
    }

    public void showToast(String toast) {
        Toast.makeText(activity,toast,Toast.LENGTH_SHORT).show();
    }
}
